package encome.work.controller;

import encome.work.dao.User;
import encome.work.service.UserService;
import encome.work.utils.RedisUtils;
import encome.work.utils.Result;
import encome.work.utils.SecurityUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private UserService userService;

    @Resource
    private RedisUtils redisUtils;

    @RequestMapping("/user")
    public Result getUser() {
        User user = SecurityUtils.getUser();
        user.setName("张三");
        userService.update(user);
        redisUtils.delKey("userInfo_" + SecurityUtils.getUsername());
        redisUtils.setValueTime("userInfo_" + user.getUsername(), user, 5);
        return Result.success("ok", user);
    }
}
